# -*- coding: utf-8 -*-
import os


# 遍历文件夹
def walkFile(file):
    sum=0
    for root, dirs, files in os.walk(file):
        # root 表示当前正在访问的文件夹路径
        # dirs 表示该文件夹下的子目录名list
        # files 表示该文件夹下的文件list
        # 遍历文件
        for f in files:
            filepath=os.path.join(root, f)
            if filepath.endswith(".java") or filepath.endswith(".xml"):
                with  open(r''+filepath, 'r',encoding='UTF-8') as f:
                    count = len(f.readlines())
                    sum+=count
    print(sum)
def main():
    walkFile("D:/myworkspace/as_workspace/Inenvironment")

if __name__ == '__main__':
    main()
